package com.hdjk.view.network;

import com.hdjk.view.callback.AlertLoginPwdCallBack;
import com.hdjk.view.callback.AlertPhoneCallBack;
import com.hdjk.view.callback.AlertTranPwdCallBack;
import com.hdjk.view.callback.AlertUserInfoCallBack;
import com.hdjk.view.callback.CallBackListener;
import com.hdjk.view.callback.ForgetLoginPwdCallBack;
import com.hdjk.view.callback.ForgetTranPwdCheckCodeCallBack;
import com.hdjk.view.callback.ForgetTranPwdResetPwdCallBack;
import com.hdjk.view.callback.ForgetTranPwdSendCodeCallBack;
import com.hdjk.view.callback.GetHoldingFundCallBack;
import com.hdjk.view.callback.GetHoldingFundDetailCallBack;
import com.hdjk.view.callback.GetIfastUserInfoCallBack;
import com.hdjk.view.callback.GetIntegralCallBack;
import com.hdjk.view.callback.GetIntegralListCallBack;
import com.hdjk.view.callback.GetOpenAccountCodeCallback;
import com.hdjk.view.callback.GetTotalAssetsCallBack;
import com.hdjk.view.callback.GetUserIdCallBack;
import com.hdjk.view.callback.GetUserInfoCallBack;
import com.hdjk.view.callback.HistoricalTransactionCallBack;
import com.hdjk.view.callback.HistoricalTransactionGroupCallBack;
import com.hdjk.view.callback.OpenAccountCallback;
import com.hdjk.view.callback.RecommendListCallBack;
import com.hdjk.view.config.Constant;
import com.lst.projectlib.entity.Msg;
import com.zhy.http.okhttp.OkHttpUtils;

import okhttp3.Call;
import okhttp3.MediaType;

/**
 * Created by sxy on 2017/11/9.
 */

public class PersonalNetWork {
    /**
     * 发送开户验证码
     * @param jsonInfo
     * @param listener
     */
    public static void getOpenAccountIdentifyingCode(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_GET_OPEN_ACCOUNT_IDENTIFYING_CODE+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new GetOpenAccountCodeCallback() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 开户
     * @param jsonInfo
     * @param listener
     */
    public static void openAccount(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_OPEN_ACCOUNT+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new OpenAccountCallback() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取金控用户信息
     * @param token
     * @param listener
     */
    public static void getUserInfo(String token, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_USER_INFO)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new GetUserInfoCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackError(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取金控用户ID
     * @param token
     * @param listener
     */
    public static void getUserId(String token, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_USER_ID)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new GetUserIdCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取奕丰用户信息
     * @param token
     * @param listener
     */
    public static void getIfastUserInfo(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_IFAST_USER_INFO)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetIfastUserInfoCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 忘记登录密码
     * @param jsonInfo
     * @param listener
     */
    public static void forgetLoginPwd(String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.postString().url(Constant.URL_FORGET_LOGIN_PWD)
                    .mediaType(MediaType.parse(Constant.json_format))
                    .content(jsonInfo)
                    .build()
                    .execute(new ForgetLoginPwdCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 修改用户信息
     * @param jsonInfo
     * @param listener
     */
    public static void alertUserInfo(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.postString().url(Constant.URL_ALERT_USER_INFO)
                    .addHeader("Authorization","Bearer "+token)
                    .mediaType(MediaType.parse(Constant.json_format))
                    .content(jsonInfo)
                    .build()
                    .execute(new AlertUserInfoCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }
    /**
     * 修改手机号
     * @param jsonInfo
     * @param listener
     */
    public static void alertPhone(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.postString().url(Constant.URL_ALERT_PHONE)
                    .addHeader("Authorization","Bearer "+token)
                    .mediaType(MediaType.parse(Constant.json_format))
                    .content(jsonInfo)
                    .build()
                    .execute(new AlertPhoneCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 修改登录密码
     * @param jsonInfo
     * @param listener
     */
    public static void alertLoginPwd(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.postString().url(Constant.URL_ALERT_LOGIN_PWD)
                    .addHeader("Authorization","Bearer "+token)
                    .mediaType(MediaType.parse(Constant.json_format))
                    .content(jsonInfo)
                    .build()
                    .execute(new AlertLoginPwdCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 修改交易密码
     * @param jsonInfo
     * @param listener
     */
    public static void alertTranPwd(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_ALERT_TRAN_PWD+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new AlertTranPwdCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 忘记交易密码发送验证码
     * @param jsonInfo
     * @param listener
     */
    public static void forgetTranPwdSendCode(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_FORGET_TRAN_PWD_SEND_CODE+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new ForgetTranPwdSendCodeCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }
    /**
     * 忘记交易密码校验验证码
     * @param jsonInfo
     * @param listener
     */
    public static void forgetTranPwdCheckCode(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_FORGET_TRAN_PWD_CHECK_CODE+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new ForgetTranPwdCheckCodeCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 忘记交易密码校验验证码
     * @param jsonInfo
     * @param listener
     */
    public static void forgetTranPwdResetPwd(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_FORGET_TRAN_PWD_RESET_PWD+"&paramList="+jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new ForgetTranPwdResetPwdCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取账户总资产
     * @param jsonInfo
     * @param listener
     */
    public static void getTotalAssets(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_ACCOUNT_TOTAL_ASSETS)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetTotalAssetsCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取账户持有基金资产列表
     * @param jsonInfo
     * @param listener
     */
    public static void getHoldingFund(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_ACCOUNT_HOLDING_FUND)
                    .addHeader("Authorization", "Bearer " + token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetHoldingFundCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取账户持有基金资产详情
     * @param jsonInfo
     * @param listener
     */
    public static void getHoldingFundDetail(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_ACCOUNT_HOLDING_FUND)
                    .addHeader("Authorization", "Bearer " + token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetHoldingFundDetailCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取账户基金和理财历史交易记录
     * @param jsonInfo
     * @param listener
     */
    public static void getHistoricalTransactionList(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_HISTORICAL_TRANSACTION_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new HistoricalTransactionCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取账户组合历史交易记录
     * @param jsonInfo
     * @param listener
     */
    public static void getGroupHistoricalTransactionList(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_GROUP_HISTORICAL_TRANSACTION_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new HistoricalTransactionGroupCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取推荐列表
     * @param token
     * @param listener
     */
    public static void getRecommendList(String token, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_RECOMMEND_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new RecommendListCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取积分
     * @param token
     * @param listener
     */
    public static void getIntegral(String token, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_INTEGRAL)
                        .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new GetIntegralCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取积分收支列表
     * @param token
     * @param listener
     */
    public static void getIntegralList(String token, String jsonInfo,final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_INTEGRAL_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("page",jsonInfo)
                    .build()
                    .execute(new GetIntegralListCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
//                            if (arg1.toString().contains("request failed , reponse's code is : 401")){
//                                Preferences pre = new Preferences(Appconfig.instance);
//                                pre.setToken("");
//                                pre.setUserName("");
//                                pre.setHoldingCode(0);
//                                ToastUtils.showLongToast(Appconfig.instance,"登录超时，请重新登录");
//                                return;
//                            }
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }
}
